package com.leesche.zcsp.node.net.service.impl;

import com.leesche.zcsp.node.net.service.data.NetDevice;
import com.leesche.zcsp.node.net.service.NetDeviceService;
import com.leesche.zcsp.node.net.timer.DeviceTimer;
import com.leesche.zcsp.node.web.service.PubDeviceService;
import com.leesche.zcsp.node.web.service.impl.data.read.PubDeviceDto;
import com.leesche.zcsp.node.web.service.impl.data.read.QueryPubDeviceCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by dennies yang  on 2016-11-03.
 */
@Service
public class NetDeviceServiceImpl implements NetDeviceService {
    @Autowired
    PubDeviceService pubDeviceService;

    /**
     * <p>获取设备信息 </p>
     * @param deviceName 设备名称  对应设备的IMME
     * @return
     */
    public NetDevice getNetDevice(String deviceName) {
        if (!DeviceTimer.deviceMap.containsKey(deviceName)) {
            addDevice(deviceName);
        }
        return DeviceTimer.deviceMap.get(deviceName);
//        return DeviceTimer.getNetDevice(deviceName);
    }

    /***
     * <P>增加设备</P>
     * @param deviceName
     */
    public void addDevice(String deviceName) {
        QueryPubDeviceCondition condition = new QueryPubDeviceCondition();
        condition.setImme(deviceName);
        PubDeviceDto pubDeviceDto = pubDeviceService.findByCondition(condition);
        if (pubDeviceDto != null) {
            DeviceTimer.addDeviceName(pubDeviceDto);
        }
    }
}
